# """
# 注意：
# api签名时：签名用私钥，验签用公钥
# 数据加密时：加密用公钥，解密用私钥
# 密钥和公钥保存的图片会在下边展示出来
# """
# import rsa
# # 对api的签名机制进行验证：签名用私钥，验签用公钥



# # from Commons.filePath import FilePath  
# # imgconfig=Config().imgConfig() 
# # appsetting=Config().appSetting() 
# # imgSavePath=FilePath("/static/common/").path()
# class RsaEncrypt:
#   def __init__(self):
#       pass
#   def rsa_generate(self):
#     """
#     生成私钥和公钥并保存
#     :return:
#     """
#     # 生成公钥和私钥
#     pubkey, privkey = rsa.newkeys(1024)
#     pub = pubkey.save_pkcs1()
#     # 公钥
#     with open('public.pem', 'wb') as w_pub:
#       w_pub.write(pub)
#     # 私钥
#     pri = privkey.save_pkcs1()
#     with open('private.pem', 'wb') as w_pri:
#       w_pri.write(pri)
#     return "保存成功"

#   def read_rsa(self):
#     """
#     读取公钥和私钥
#     """
#     with open('public.pem', 'rb') as publickfile:
#       pub = publickfile.read()
#       pubkey = rsa.PublicKey.load_pkcs1(pub)
#     with open('private.pem', 'rb') as privatefile:
#       priv = privatefile.read()
#       # print(pub)
#       privkey = rsa.PrivateKey.load_pkcs1(priv)
#     return pubkey, privkey

# # 对数据进行加密:加密用公钥，解密用私钥
# class DataEncrypt:
#   def __init__(self, data_str):
#     sing_test = RsaEncrypt()
#     self.data_str = data_str
#     self.secret_key = sing_test.read_rsa()# 调用RsaEncrypt类的读取密钥对方法
#   def data_encrypt(self):
#     """
#     用公钥对数据进行加密 
#     """
#     str_encrypt = rsa.encrypt(self.data_str.encode(), self.secret_key[0]) 
#     return str_encrypt

#   def data_decrypt(self, encrypt):
#     """ 数据解密 """
#     str = rsa.decrypt(encrypt, self.secret_key[1]).decode() 
#     return str

# # if __name__ == '__main__':

# #     # 签名生成
# #     # sing_test = RsaEncrypt()
# #     # sing_test.rsa_generate()   
# #     # 验证加密解密机制
# #     data = DataEncrypt('dfad--fa/d.s$$$&{}()><?L::>')
# #     data.data_encrypt() #数据加密
# #     data.data_decrypt() #数据解密